//组托详表

/* const {
	stringify
} = require("querystring");
 */
//右滑关闭
mui.init({
	swipeBack: true,
})
var fs = true;
var UserNO = localStorage.getItem("UserName");
console.log(UserNO)
window.onload = function() {

	mui.plusReady(function() {
		var currentwindow = plus.webview.currentWebview();
		if (currentwindow.WorkOrderNO != '' && currentwindow.WorkOrderNO != undefined) {
			$("#WorkOrderNO").val(currentwindow.WorkOrderNO);
			$("#MatNO").val(currentwindow.MaterialNO);
			$("#MaterialName").val(currentwindow.MaterialName);
			console.log(currentwindow.MaterialName);
			console.log(currentwindow.MatNO);
			console.log(currentwindow.WorkOrderNO);
		} else {
			mui.toast("未带入参数。", {
				duration: '1000',
				type: 'div'
			});
		}
		//disabled
		$("#txtLineNO").attr("disabled", true);
		$("#txtLineNO").attr("placeholder", "disabled")
		// $("#txtLineNO").css("background-color", "#cccccc")
		$("#txtBarcodeNO").attr("disabled", true);
		$("#txtBarcodeNO").attr("placeholder", "disabled")
		// $("#txtBarcodeNO").css("background-color", "#cccccc")

		//首验站位扫描
		$("#txtFirstNO").keyup(function(event) {
			var NextStationNO = '';
			if (event.keyCode == 13) {
				var txtFirstNO = $("#txtFirstNO").val();
				var workorderNO = $("#WorkOrderNO").val();
				var typesWork = $("#OrderIndex").val();
				if (txtFirstNO === null || txtFirstNO === undefined) {
					mui.toast("请扫描首验料盘条码。", {
						duration: '1000',
						type: 'div'
					});
					$("#txtFirstNO").val('');
					$("#txtFirstNO").focus();
				}
				xccpostAsync("JyhstWebASHX.ashx", {
					Action: "GetFeedStation",
					txtFirstNO: txtFirstNO,
					typesWork: typesWork,
					workorderNO: workorderNO,
					UserNO: UserNO
				}, function(data) {
					// console.log(JSON.stringify(data))
					if (data.Code == "200") {

						$("#txtLineNO").val(data.ResultData);
						plus.nativeUI.closeWaiting(); //关闭转圈圈特效
					} else {
						mui.toast("扫描失败。" + data.Message, {
							duration: '1000',
							type: 'div'
						});
						$("#txtFirstNO").val("");
						$("#txtFirstNO").focus();
						plus.nativeUI.closeWaiting(); //关闭转圈圈特效
					}
				}, function(error) {

					console.log("没有数据....");
					plus.nativeUI.closeWaiting(); //关闭转圈圈特效
				})
			}

		});


		//物料条码扫描
		$("#txtBarcodeNO").keyup(function(event) {
			console.log(event);
			if (event.keyCode == 13) {
				//$("#txtQty").focus();
				//p判断是PC端
				var BarCodeNO = $("#txtBarcodeNO").val();
				var LineNO = $("#txtLineNO").val();
				var workorderNO = $("#WorkOrderNO").val();
				var typesWork = $("#OrderIndex").val();
				if (BarCodeNO === null || BarCodeNO === undefined) {
					mui.toast("请扫描料盘条码。", {
						duration: '1000',
						type: 'div'
					});
					BarCodeNO.focus();
				}
				xccpostAsync("JyhstWebASHX.ashx", {
					Action: "QCCheckMaterials",
					BarCodeNO: BarCodeNO,
					typesWork: typesWork,
					workorderNO: workorderNO,
					LineNO: LineNO,
					UserNO: UserNO
				}, function(data) {
					console.log(JSON.stringify(data))
					if (data.Code == "200") {
						if (data.ResultData == 'End') {
							Zu();
							mui.toast("检验完成!", {
								duration: '1000',
								type: 'div'
							});
						} else {
							$("#txtLineNO").val(data.ResultData);
						}


					} else {
						mui.toast("扫描失败。" + data.Message, {
							duration: '1000',
							type: 'div'
						});
						Audios();
					}
					plus.nativeUI.closeWaiting(); //关闭转圈圈特效
					$("#txtBarcodeNO").val('');
					$("#txtBarcodeNO").focus();
				}, function(error) {
					// mui.toast("扫描失败！", {
					// 	duration: '1000',
					// 	type: 'div'
					// });
					Audios();
					console.log("没有数据....");
					$("#txtBarcodeNO").val('');
					$("#txtBarcodeNO").focus();
					plus.nativeUI.closeWaiting(); //关闭转圈圈特效
				})
			}

		});



		//关闭等待框

		plus.nativeUI.closeWaiting();
		//显示当前页面
		//mui.currentWebview.show();
	});
}

//表单判定
function VaDate() {
	console.log($("#txtQty").val());
	if ($("#Lingliaodanhao").val().replace(/ /g, "") == "") {
		mui.toast('请扫描条码', {
			duration: '1000',
			type: 'div'
		})
		$("#Lingliaodanhao").focus();
		return false
	}

	return true;
}

//失败报警
function Audios() {
	var audio = new Audio('../../../fonts/baojin.mp3');

	audio.play();
}

//首验开始
function Zu() {
	console.log(fs);
	if (fs) {
		fs = false;
		$("#txtFirstNO").attr("disabled", true);
		$("#txtFirstNO").attr("placeholder", "disabled");
		// $("#txtLineNO").attr("disabled", false);
		// $("#txtLineNO").attr("placeholder", "自动检测站位");
		$("#txtBarcodeNO").attr("disabled", false);
		$("#txtBarcodeNO").attr("placeholder", "请扫描料盘条码");
		$("#btnZu").text("首验结束");
		$("#btnZu").css("background-color", "firebrick");
		//#4cd964

		$("#txtBarcodeNO").focus();
	} else {
		fs = true;
		//txtFirstNO.Enabled = false;
		$("#txtFirstNO").attr("disabled", false);
		$("#txtFirstNO").attr("placeholder", "请扫描首验站位");
		// $("#txtLineNO").attr("disabled", true);
		// $("#txtLineNO").attr("placeholder", "disabled");
		$("#txtBarcodeNO").attr("disabled", true);
		$("#txtBarcodeNO").attr("placeholder", "disabled");
		$("#btnZu").text("首验开始");
		$("#btnZu").css("background-color", "#4cd964");
		$("#txtFirstNO").val('');
		$("#txtLineNO").val('');
		$("#txtFirstNO").focus();

	}

};